package com.cn.sl.server.api.system.role.model.entity

import com.cn.sl.server.api.system.menu.model.entity.MenuEntity
import com.cn.sl.server.api.system.user.model.entity.AdminUserEntity
import com.cn.sl.server.common.model.EditableEntity
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.JoinTable
import jakarta.persistence.ManyToMany
import jakarta.persistence.OrderBy
import jakarta.persistence.Table

@Table(name = "role")
@Entity
class RoleEntity : EditableEntity<AdminUserEntity>() {
    var name: String = ""

    var memo: String? = ""

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
        name = "user_role",
        joinColumns = [JoinColumn(name = "role_id")],
        inverseJoinColumns = [JoinColumn(name = "user_id")]
    )
    var users: List<AdminUserEntity> = arrayListOf()

    @ManyToMany(fetch = FetchType.EAGER)
    @OrderBy("id")
    @JoinTable(
        name = "role_menu",
        joinColumns = [JoinColumn(name = "role_id")],
        inverseJoinColumns = [JoinColumn(name = "menu_id")]
    )
    var menus: List<MenuEntity> = arrayListOf()
}